/**
 * Created by 沈小鱼 on 2016/8/6.
 */
$(function(){
    $(document).ready(function(){
        $(".contact-box").each(function(){
            animationHover(this,"pulse")
        });
    });
    $(window).load(function(){
        goInfo();
        goMeet(1);
        goIll(1);
        goFamily(1);
        goExperience(1);
        goRequirement();
        goPhoto();
        goComment(1);
        var mydate = new Date();
        var year = mydate.getFullYear(); //获取完整的年份(4位,1970-????)
        var mon = mydate.getMonth(); //获取当前月份(0-11,0代表1月),
        var day = mydate.getDate(); //获取当前月份(0-11,0代表1月),
        if(mon<9){
            mon = '0'+(mon+1);
        }else{
            mon = mon+1
        }
        if(day<=9){
            day = '0'+(day);
        }
        $('#usermeeting-mm_date').val( year+'-'+mon+'-'+day);
    });
    $('#userinfo-mi_birth').change(function(){
        var str = this.value.substr(0,4)*1;
        var arr = ['猴','鸡','狗','猪','鼠','牛','虎','兔','龙','蛇','马','羊'];
        index = str%12
        $('#userinfo-mi_zodiac').val(arr[index]);
    });
    $('#info_privince').change(function(){
        csrfToken = $('meta[name="csrf-token"]').attr("content");
        privince_id = $('#info_privince option:selected').val();
        city = $('#info_city');
        city_html = '';
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                        layer.close(index);
                        window.top.location.href='/marriage/admin/web/index.php/'
                        return false;
                    });
                }
            }
        });
        $.post('/marriage/admin/web/index.php/user/areachange',{
            '_marriage-admin':csrfToken,
            'area_id':privince_id,
            'level':1,
        },function(data){
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                city.empty();
                res = data.data;
                cities = res.cities;
                $.each(cities,function(index,item){
                    city_html+='<option value="'+index+'">'+item+'</option>';
                });
                city.append(city_html);
                return false;
            }else{
                ShowMessage(data.status,data.message);
                $(this).val('320000');
                return false;
            }
        },'json');
    });
    $('#extra_privince').change(function(){
        csrfToken = $('meta[name="csrf-token"]').attr("content");
        privince_id = $('#extra_privince option:selected').val();
        city = $('#extra_city');
        city_html = '';
        district = $('#extra_district');
        district_html = '';
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1},function(index){
                        layer.close(index);
                        window.top.location.href='/marriage/admin/web/index.php/'
                        return false;
                    });
                }
            }
        });
        $.post('/marriage/admin/web/index.php/user/areachange',{
            '_marriage-admin':csrfToken,
            'area_id':privince_id,
            'level':1,
        },function(data){
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                city.empty();
                district.empty();
                res = data.data;
                cities = res.cities;
                districts = res.districts;
                $.each(cities,function(index,item){
                    city_html+='<option value="'+index+'">'+item+'</option>';
                });
                $.each(districts,function(index,item){
                    district_html+='<option value="'+index+'">'+item+'</option>';
                });
                city.append(city_html);
                district.append(district_html);
                return false;
            }else{
                ShowMessage(data.status,data.message);
                $(this).val('320000');
                return false;
            }
        },'json');
    });
    $('#extra_city').change(function(){
        csrfToken = $('meta[name="csrf-token"]').attr("content");
        city_id = $('#extra_city option:selected').val();
        district = $('#extra_district');
        district_html = '';
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                        layer.close(index);
                        window.top.location.href='/marriage/admin/web/index.php/'
                        return false;
                    });
                }
            }
        });
        $.post('/marriage/admin/web/index.php/user/areachange',{
            '_marriage-admin':csrfToken,
            'area_id':city_id,
            'level':2,
        },function(data){
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                district.empty();
                res = data.data;
                districts = res.districts;
                $.each(districts,function(index,item){
                    district_html+='<option value="'+index+'">'+item+'</option>';
                });
                district.append(district_html);
                return false;
            }else{
                ShowMessage(data.status,data.message);
                $(this).val('320400');
                return false;
            }
        },'json');
    });
    $('#detail_privince').change(function(){
        csrfToken = $('meta[name="csrf-token"]').attr("content");
        privince_id = $('#detail_privince option:selected').val();
        city = $('#detail_city');
        city_html = '';
        district = $('#detail_district');
        district_html = '';
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                        layer.close(index);
                        window.top.location.href='/marriage/admin/web/index.php/'
                        return false;
                    });
                }
            }
        });
        $.post('/marriage/admin/web/index.php/user/areachange',{
            '_marriage-admin':csrfToken,
            'area_id':privince_id,
            'level':1,
        },function(data){
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                city.empty();
                district.empty();
                city.removeAttr('disabled');
                district.removeAttr('disabled');
                res = data.data;
                cities = res.cities;
                districts = res.districts;
                $.each(cities,function(index,item){
                    city_html+='<option value="'+index+'">'+item+'</option>';
                });
                $.each(districts,function(index,item){
                    district_html+='<option value="'+index+'">'+item+'</option>';
                });
                city.append(city_html);
                district.append(district_html);
                return false;
            }else{
                ShowMessage(data.status,data.message);
                $(this).val('320000');
                return false;
            }
        },'json');
    });
    $('#detail_city').change(function(){
        csrfToken = $('meta[name="csrf-token"]').attr("content");
        city_id = $('#detail_city option:selected').val();
        district = $('#detail_district');
        district_html = '';
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                        layer.close(index);
                        window.top.location.href='/marriage/admin/web/index.php/'
                        return false;
                    });
                }
            }
        });
        $.post('/marriage/admin/web/index.php/user/areachange',{
            '_marriage-admin':csrfToken,
            'area_id':city_id,
            'level':2,
        },function(data){
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                district.empty();
                res = data.data;
                districts = res.districts;
                $.each(districts,function(index,item){
                    district_html+='<option value="'+index+'">'+item+'</option>';
                });
                district.append(district_html);
                return false;
            }else{
                ShowMessage(data.status,data.message);
                $(this).val('320400');
                return false;
            }
        },'json');
    });
    $('#userdetail-md_marry').change(function(){
        $('#md_despid').hide();
        $('#md_child').hide();
        $('#md_child_belong').hide();
        $("#userdetail-md_child_belong").val('');
        $("#userdetail-md_despid").val('');
        $('#md_child_belong').val('');
        $('input:radio[name="UserDetail[md_child]"]').attr('checked',false);
        if($(this).val()=='离异'){
            $('#md_despid').show();
            $('#md_child').show();
        }else if($(this).val()=='丧偶'){
            $('#md_child').show();
        }
    });
    $('input:radio[name="UserDetail[md_child]"]').change(function(){
        $('#md_child_belong').hide();
        $("#userdetail-md_child_belong").val('');
        if($(this).val()=='有'){
            $('#md_child_belong').show();
        }
    });
    $('#md_isowner').click(function(){
        $('#userdetail-md_isowner').val('无');
        $('#house_location').hide();
        $('#house_address').hide();
        $('#house_area').hide();
        $('#detail_privince').val('0');
        $('#detail_city').empty();
        $('#detail_district').empty();
        $('#detail_city').html('<option value="0" selected>请先选择省份</option>');
        $('#detail_district').html('<option value="0" selected>请先选择省份</option>');
        $('#userdetail-md_house_area').val('');
        $('#userdetail-md_house_address').val('');
        if($(this).is(':checked')){
            $('#userdetail-md_isowner').val('有');
            $('#house_location').show();
            $('#house_address').show();
            $('#house_area').show();
        }
    });
    $('#md_loan').click(function(){
        $('#userdetail-md_loan').val('无');
        if($(this).is(':checked')){
            $('#userdetail-md_loan').val('有');
        }
    });
    $('#md_hascar').click(function(){
        $('#userdetail-md_hascar').val('无');
        $('#car_type').hide();
        $('#userdetail-md_cartype').val('');
        if($(this).is(':checked')){
            $('#userdetail-md_hascar').val('有');
            $('#car_type').show();
        }
    });
    $("#user_edit").on('beforeSubmit',function(e){
        main_photo = window.top.document.getElementById('main_photo');
        photo_main = window.top.document.getElementById('photo_main');
        $('#userdetail-md_location').attr('value','');
        info_privince = $('#info_privince option:selected').text();
        info_city = $('#info_city option:selected').text();
        extra_privince = $('#extra_privince option:selected').text();
        extra_city = $('#extra_city option:selected').text();
        extra_district = $('#extra_district option:selected').text();
        $('#userinfo-mi_root').attr('value',info_privince+';'+info_city);
        $('#userextra-me_postion').attr('value',extra_privince+';'+extra_city+';'+extra_district);
        md_marry = $('#userdetail-md_marry').val();
        md_child = $('input:radio[name="UserDetail[md_child]"]:checked').val();
        md_despid = $('#userdetail-md_despid').val();
        child_belong = $('#userdetail-md_child_belong').val();
        if($('#md_isowner').is(':checked')){
            detail_privince = $('#detail_privince option:selected').val();
            detail_city = $('#detail_city option:selected').val();
            detail_district = $('#detail_district option:selected').val();
            md_house_area = $('#userdetail-md_house_area').val();
            if((detail_privince=='0'||detail_privince=='')||(detail_city=='0'||detail_city=='')||(detail_district=='0'||detail_district=='')){
                layer.alert('请选择房屋地址所在',{icon: 0,closeBtn:0},function(index){
                    layer.close(index);
                });
                return false;
            }
            $('#userdetail-md_location').attr('value',
                $('#detail_privince option:selected').text()+';'+
                $('#detail_city option:selected').text()+';'+
                $('#detail_district option:selected').text());
        }
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status == '200'){
                    $('#myInfoDialog').modal('hide');
                    main_photo.src = data.data;
                    photo_main.href = data.data;
                    goInfo();
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myMettingDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#meetting-form")[0].reset();//重置表单
        if(data=='add') {
            var mydate = new Date();
            var year = mydate.getFullYear(); //获取完整的年份(4位,1970-????)
            var mon = mydate.getMonth(); //获取当前月份(0-11,0代表1月),
            var day = mydate.getDate(); //获取当前月份(0-11,0代表1月),
            if(mon<9){
                mon = '0'+(mon+1);
            }else{
                mon = mon+1
            }
            if(day<=9){
                day = '0'+(day);
            }
            $("#usermeeting-mm_id").val("");
            $("#usermeeting-mm_date").val(year+'-'+mon+'-'+day);
        } else{
            $("#usermeeting-mm_id").val(data.mm_id);
            $("#usermeeting-mu_targrt").val(data.mu_id);
            $("#usermeeting-mm_date").val(data.mm_date);
        }
    });
    $("#meetting-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goMeet(1);
                    $('#myMettingDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myIllDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#ill-form")[0].reset();//重置表单
        if(data=='add') {
            $("#userill-mi_id").val("");
        } else{
            $("#userill-mi_id").val(data.mi_id);
            $("#userill-mi_type").val(data.mi_type);
            $("#userill-mi_cure").find('[value="'+data.mi_cure+'"]').attr('checked',true);
        }
    });
    $("#ill-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goIll(1);
                    $('#myIllDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myFamilyDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#family-form")[0].reset();//重置表单
        if(data=='add') {
            $("#userfamily-mf_id").val("");
        } else{
            $("#userfamily-mf_id").val(data.mf_id);
            $("#userfamily-mr_id").val(data.mr_id);
            $("#userfamily-mf_name").val(data.mf_name);
            $("#userfamily-mf_age").val(data.mf_age);
            $("#userfamily-mf_type").val(data.mf_type);
            $("#userfamily-mf_phone").val(data.mf_phone);
        }
    });
    $("#family-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goFamily(1);
                    $('#myFamilyDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myExperienceDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#experience-form")[0].reset();//重置表单
        if(data=='add') {
            $("#userexperience-me_id").val("");
        } else{
            $("#userexperience-me_id").val(data.me_id);
            $("#userexperience-me_discription").val(data.me_discription);
        }
    });
    $("#experience-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goExperience(1);
                    $('#myExperienceDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myCommentDialog').on('show.bs.modal', function (event) {
        $("#comment-form")[0].reset();//重置表单
    });
    $("#comment-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goComment(1);
                    $('#myCommentDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myRequirementDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#requirement-form")[0].reset();//重置表单
        if(data=='add') {
            $("#userrequirements-mr_id").val("");
        } else{
            $("#userrequirements-mr_id").val(data.mr_id);
            $("#userrequirements-mr_work").val(data.mr_work);
            $("#userrequirements-mr_ecom").val(data.mr_ecom);
            $("#userrequirements-mr_home").val(data.mr_home);
            $("#userrequirements-mr_edu").val(data.mr_edu);
            $("#userrequirements-mr_looks").val(data.mr_looks);
            $("#userrequirements-mr_figure").val(data.mr_figure);
            $("#userrequirements-mr_house").val(data.mr_house);
            $("#userrequirements-mr_car").val(data.mr_car);
            $("#userrequirements-mr_isdissociated").find('[value="'+data.mr_isdissociated+'"]').attr('checked',true);
            $("#userrequirements-mr_hadchild").find('[value="'+data.mr_hadchild+'"]').attr('checked',true);
            $("#userrequirements-mr_issick").find('[value="'+data.mr_issick+'"]').attr('checked',true);
            $("#userrequirements-mr_withparents").find('[value="'+data.mr_withparents+'"]').attr('checked',true);
            $("#userrequirements-mr_wantchild").find('[value="'+data.mr_wantchild+'"]').attr('checked',true);
            $("#userrequirements-mr_quickmerry").find('[value="'+data.mr_quickmerry+'"]').attr('checked',true);
            $("#userrequirements-mr_merryperiod").val(data.mr_merryperiod);
            $("#userrequirements-mr_other").val(data.mr_other);
        }
    });
    $("#requirement-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goRequirement();
                    $('#myRequirementDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
    $('#myPhotoDialog').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var data = button.data('data');
        $("#photo-form")[0].reset();//重置表单
        if(data=='') {
            $('#userphoto-url').val('');
        } else{
            $('#userphoto-url').val(data.mp_other);
        }
    });
    $("#photo-form").on('beforeSubmit',function(e){
        $.ajax({
            statusCode: {
                302: function() {
                    layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }
            },
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            beforeSend: function () {
                ShowLoad();
            },
            complete: function () {
                layer.closeAll('loading');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('发生错误', {icon: 5});
                return false;
            },
            success: function (data) {
                ShowMessage(data.status,data.message);
                if(data.status == '302'){
                    layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                        window.top.location.href='/marriage/admin/web/index.php/';
                    });
                    return false;
                }else if(data.status=='200'){
                    goPhoto();
                    $('#myPhotoDialog').modal('hide');
                    return false;
                }else{
                    return false;
                }
            }
        });
        return false;
    });
});

function clearNoNum(obj) {
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g,"");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g,"");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g,".");
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}

function goInfo(){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-info").data("id"),
        data:{"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-info').html(data);
            return false;
        }
    });
}

function goMeet(page){
    page!=null? $("[name='meet_page']").val(page):null;
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-meeting").data("id"),
        data:{"page":page,"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-meeting').html(data);
            return false;
        }
    });
}

function goIll(page){
    page!=null? $("[name='ill_page']").val(page):null;
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-ill").data("id"),
        data:{"page":page,"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-ill').html(data);
            return false;
        }
    });
}

function goFamily(page){
    page!=null? $("[name='family_page']").val(page):null;
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-family").data("id"),
        data:{"page":page,"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-family').html(data);
            return false;
        }
    });
}

function goExperience(page){
    page!=null? $("[name='experience_page']").val(page):null;
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-experience").data("id"),
        data:{"page":page,"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-experience').html(data);
            return false;
        }
    });
}

function goComment(page){
    page!=null? $("[name='comment_page']").val(page):null;
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-comment").data("id"),
        data:{"page":page,"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-comment').html(data);
            return false;
        }
    });
}

function goRequirement(){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-requirement").data("id"),
        data:{"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-requirement').html(data);
            return false;
        }
    });
}

function goPhoto(){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }
        },
        url: $("#user-photos").data("id"),
        data:{"_marriage-admin":csrfToken},
        beforeSend: function () {
            ShowLoad();
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.alert('发生错误', {icon: 5});
            return false;
        },
        success: function (data) {
            layer.closeAll('loading');
            $('#user-photos').html(data);
            return false;
        }
    });
}

function MeetDel(id){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该约会记录？',{icon: 0, title:'提示'},function(index){
        layer.close(index);
        ShowLoad();
        $.post('/marriage/admin/web/index.php/meet/del',{
            'mm_id':id,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                goMeet(1);
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function IllDel(id){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该病历？',{icon: 0, title:'提示'},function(index){
        ShowLoad();
        $.post('/marriage/admin/web/index.php/ill/del',{
            'mi_id':id,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                layer.close(index);
                goIll(1);
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function FamilyDel(id){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该成员？',{icon: 0, title:'提示'},function(index){
        ShowLoad();
        $.post('/marriage/admin/web/index.php/family/del',{
            'mf_id':id,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                layer.close(index);
                goFamily(1);
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function ExperienceDel(id){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该记录？',{icon: 0, title:'提示'},function(index){
        ShowLoad();
        $.post('/marriage/admin/web/index.php/experience/del',{
            'me_id':id,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                layer.close(index);
                goExperience(1);
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function CommentDel(id){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该记录？',{icon: 0, title:'提示'},function(index){
        ShowLoad();
        $.post('/marriage/admin/web/index.php/comment/del',{
            'mc_id':id,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                layer.close(index);
                goComment(1);
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function PhotoDel(id,url){
    csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        statusCode: {
            302: function() {
                layer.alert('登录信息已过期，请重新登录',{icon: 1,closeBtn:0},function(index){
                    layer.close(index);
                    window.top.location.href='/marriage/admin/web/index.php/';
                    return false;
                });
            }
        }
    });
    layer.confirm('确认删除该相片？',{icon: 0, title:'提示'},function(index){
        ShowLoad();
        $.post('/marriage/admin/web/index.php/photo/del',{
            'mp_id':id,'url':url,
            '_marriage-admin':csrfToken
        },function(data){
            ShowMessage(data.status,data.message);
            if(data.status == '302'){
                layer.alert('登录信息已过期，请重新登录',{icon: 0,closeBtn:0},function(){
                    window.top.location.href='/marriage/admin/web/index.php/';
                });
                return false;
            }else if(data.status == '200'){
                ShowMessage(data.status,data.message);
                layer.close(index);
                goPhoto();
                return true;
            }else{
                ShowMessage(data.status,data.message);
                return false;
            }
        },'json');
    });
}

function goMeetPage(obj){
    var page=$(obj).data('page')+1;
    goMeet(page);
    return false;
}

function goIllPage(obj){
    var page=$(obj).data('page')+1;
    goIll(page);
    return false;
}

function goFamilyPage(obj){
    var page=$(obj).data('page')+1;
    goFamily(page);
    return false;
}

function goExperiencePage(obj){
    var page=$(obj).data('page')+1;
    goExperience(page);
    return false;
}

function goCommentPage(obj){
    var page=$(obj).data('page')+1;
    goComment(page);
    return false;
}